package me.yuxiaoyao.lock.redis;

import me.yuxiaoyao.lock.LockExecutor;
import org.springframework.integration.redis.util.RedisLockRegistry;

import java.util.concurrent.locks.Lock;


/**
 * @author kerryzhang on 2020/12/21
 */


public class RedisLockExecutor implements LockExecutor {

    private final RedisLockRegistry redisLockRegistry;

    public RedisLockExecutor(RedisLockRegistry redisLockRegistry) {
        this.redisLockRegistry = redisLockRegistry;
    }


    @Override
    public Lock getLock(Object lockKey) {
        // current redis key only support String type
        return redisLockRegistry.obtain(lockKey.toString());
    }

}
